<template>
  <div>
    <div class="history">
      <div class="top">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearFn" />
      </div>
      <div class="down" v-if="ifShowHistory">
        <van-tag v-for="(item,index) in historyKeywordList" @click="tagClick(item)" :key="index" plain type="default">{{item}}</van-tag>
      </div>
    </div>

    <div class="history">
      <div class="top">
        <h4>热门搜索</h4>
      </div>
      <div class="down">
        <van-tag v-for="(item,index) in hotKeywordList" @click="tagClick(item.keyword)" :key="index" plain :type="item.is_hot == 1 ? 'danger' : 'default'">{{item.keyword}}</van-tag>
      </div>
    </div>
  </div>
</template>

<script>
import { ClearHistory } from '../../request/api'
export default {
  name: "HistoryHot",
  props: ['historyKeywordList', 'hotKeywordList'],
  data() {
    return {
      ifShowHistory: true
    }
  },
  methods: {
    // 点击tag后进行搜索事件
    tagClick(item) {
      this.$emit('tagClick', item)
    },
    // 清除历史记录
    clearFn() {
      ClearHistory().then(res => {
        if (res.errno == 0) {
          this.$toast.success('删除成功');
          setTimeout(() => {
          this.ifShowHistory = false
          },500)
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.history {
  padding: 0 2%;
  background-color: #fff;
  margin-bottom: .2rem;
  .top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: .5rem;
    font-size: .2rem;
    h4 {
      font-weight: normal;
      font-size: .18rem;
    }
  }
  .down {
    .van-tag {
      font-size: .14rem;
      margin-right: .1rem;
      margin-bottom: .1rem;
      padding: .03rem;
    }
  }
}
</style>